package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmChannelDto;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.wemedia.service.WmChannelService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/api/v1/channel")
@RequiredArgsConstructor
public class WmChannelController {

    private final WmChannelService wmChannelService;

    @GetMapping("/channels")
    public ResponseResult channels() {
        return wmChannelService.channels();
    }

    @PostMapping("/save")
    public ResponseResult insert(@RequestBody WmChannel wmChannel) {
        log.info(wmChannel.toString());
        return wmChannelService.channelSave(wmChannel);
    }

    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmChannelDto dto) {
        log.info(dto.toString());
        return wmChannelService.findList(dto);
    }

    @PostMapping("/update")
    public ResponseResult channeelUpdate(@RequestBody WmChannel wmChannel) {
        log.info(wmChannel.toString());
        return wmChannelService.channeelUpdate(wmChannel);
    }

    @GetMapping("/del/{id}")
    public ResponseResult delete(@PathVariable Integer id) {
        log.info(id.toString());
        return wmChannelService.delete(id);
    }

}
